package com.shigu.appVersion.action;

import com.opentae.data.mall.beans.ManagerPageConstant;
import com.shigu.MallResponse;
import com.shigu.PageResponse;
import com.shigu.appVersion.bo.UploadUrlRequest;
import com.shigu.appVersion.bo.VersionRequest;
import com.shigu.appVersion.service.AdminVersionService;
import com.shigu.appVersion.service.VersionService;
import com.shigu.appVersion.vo.DownLoadResponse;
import com.shigu.appVersion.vo.SomethingResponse;
import com.shigu.appVersion.vo.VersionResponse;
import com.shigu.constant.bo.MyconstantsRequest;
import com.shigu.exceptions.AdminException;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;

/*
 * create by  过儿  2019-06-19
 * 版本相关控制层
 */
@RequestMapping("adminjson")
@Controller
public class AdminVersionController {

    @Autowired
    AdminVersionService adminVersionService;

    @RequestMapping("getVersionConstant")
    @ResponseBody
    public PageResponse<ManagerPageConstant> getVersionConstant(){
        return adminVersionService.getVersionConstant();
    }

    @RequestMapping("selOsConstant")
    @ResponseBody
    public PageResponse<ManagerPageConstant> selOsConstant(MyconstantsRequest request){
        return adminVersionService.selOsConstant(request.getPageUri());
    }

    @RequestMapping("uploadApk")
    @ResponseBody
    public MallResponse uploadApk(@Valid UploadUrlRequest request, BindingResult result) throws AdminException {
        if(result.hasErrors()){
            throw new AdminException(result.getFieldError().getDefaultMessage());
        }
        adminVersionService.uploadApk(request.getUrl());
        return new MallResponse();
    }
}
